package com.csi.sai.bl.history;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.csi.sai.data.entities.Demand;
import com.csi.sai.data.entities.HistoryDemand;
import com.csi.sai.utilities.Constants;
import com.csi.sai.utilities.Utilities;

public class HistoryRecordProcess {

	public ArrayList<HistoryDemand> getHistoryRecordDemand(Connection conn, PreparedStatement ps, ResultSet rs, int idDemand) {

		ArrayList<HistoryDemand> historyList = new  ArrayList<>();
		try {
			ps = conn.prepareStatement(Constants.CALL_PROCEDURE_DEMAND);
			Demand d = new Demand();
			d.setIdDemand(idDemand);
			Utilities.generatePreparedStatement(ps, 4, d);
			
			rs = ps.executeQuery();
			
			while(rs.next()) {
				HistoryDemand history = new HistoryDemand();
				history.setIdHistorial(rs.getInt(1));
				history.setIdSolicitud(rs.getInt(2));
				history.setFechaHist(rs.getString(3));
				history.setEstatusHist(rs.getString(4));
				history.setComentariosHist(rs.getString(5));
				history.setIdEmpleado(rs.getInt(6));
				history.setNombreEmpleado(rs.getString(7)+" "+rs.getString(8)+" "+rs.getString(9));
				historyList.add(history);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			Utilities.finallyProcess(conn, ps, rs);
		}
		
		return historyList;
	}
}
